function ajaxRequest(type, url, data, callback, loading, cache, isParent) {
    var ajaxConfig = {
        url: '',
        data: {},
        callback: null,
        loading: true,
        cache: true,
        async: true
    };
    // 判断每一个参数url的类型
    // 如果是对象则是请求参数对象
    // 如果是字符串则是请求URL，参数和回调要继续检测后面的参数
    if (typeof url === 'string') {
        ajaxConfig.url = url;
        ajaxConfig.data = data;
        ajaxConfig.callback = callback;
        ajaxConfig.loading = typeof(loading) === 'undefined' ? true : loading;
        ajaxConfig.cache = cache;
    } else {
        ajaxConfig = $.extend({}, ajaxConfig, url);
    }
    var index = null;
    $.ajax({
        type: type,
        url: ajaxConfig.url,
        data: ajaxConfig.data,
        beforeSend: function() {
            if (ajaxConfig.loading) {
                if (isParent) {
                    index = layer.load(2, {time: 10*1000});
                } else {
                    index = parent.layer.load(2, {time: 10*1000});
                }
            }
        },
        dataType: 'json',
        cache: ajaxConfig.cache,
        async: ajaxConfig.async,
        success: function(result) {
            if (ajaxConfig.loading) {
                if (isParent) {
                    layer.close(index);
                } else {
                    parent.layer.close(index);
                }
            }
            if (result.status === "success") {
                ajaxConfig.callback(result.data);
            } else {
                alert("加载后台程序出现问题，请联系管理员");
            }
        },
        error: function(result) {
            if (ajaxConfig.loading) {
                if (isParent) {
                    layer.close(index);
                } else {
                    parent.layer.close(index);
                }
            }
            console.error(result);
        }
    })
}
function ajaxGet(url, data, callback, loading, isParent) {
    ajaxRequest('GET', url, data, callback, loading, true, isParent);
}
function ajaxPost(url, data, callback, loading, isParent) {
    ajaxRequest('POST', url, data, callback, loading, false, isParent);
}